package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired(required = false)
    private AddressMapper addressMapper;

    /**
     * 1.添加收货地址
     * 请求地址：/address/insert
     * 请求方法：POST
     * 请求体数据：receiver=收件人、address=收件地址、email=邮箱、mobile=手机号、tag=标签
     * 返回响应：String "添加成功"
     */
    @RequestMapping("/insert")
    public String insertAddress(Address address){
        addressMapper.insertAddress(address);
        return "添加地址成功";
    }

    /**
     * 2.查询收货地址
     * 请求地址：/address/select
     * 请求方法：GET
     * 查询参数：无
     * 返回响应： List<Address>
     */
    @RequestMapping("/select")
    public List<Address> selectAddressList(){
        return addressMapper.selectAddressList();
    }

    /**
     * 3.删除收货地址
     * 请求地址：/address/delete
     * 请求方法：POST
     * 请求体数据：id=地址id
     * 返回响应：String "删除成功"
     */
    @RequestMapping("/delete")
    public String deleteAddress(Integer id){
        addressMapper.deleteAddress(id);
        return "删除地址成功";
    }

    /**
     * 4.修改收货地址
     * 请求地址：/address/update
     * 请求方法：POST
     * 请求体数据：id=xx&receiver=xx&address=xx&email=xxx&mobile=xx&tag=xx
     * 返回响应：String "修改成功"
     */
    @RequestMapping("/update")
    public String updateAddress(Address address){
        addressMapper.updateAddress(address);
        return "修改地址成功";
    }
}
